package com.ccc.mq.consumer;

import com.ccc.test.common.constant.MQConstant;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 消息消费者(接收消息)——自定义请求头参数
 * @author superC
 * @version 1.0.0
 * @date 2022/9/15
 */

@Component
@RocketMQMessageListener(
        nameServer = "${base.config.rocketmq.nameServer}",
        topic = "${base.config.rocketmq.topic.myheaderTopic}",
        consumerGroup = "${base.config.rocketmq.consumer.group.myheaderGroup}"
)
public class MessageHeaderConsumerService implements RocketMQListener<Message> {
    protected static final Logger logger = LoggerFactory.getLogger(MessageHeaderConsumerService.class);

    @Override
    public void onMessage(Message message) {
        logger.info("=======消息消费者-监听 receiveLog========");
        String headerMethod = message.getProperty(MQConstant.HEADER_METHOD);
        logger.info("===headerMethod: {}", headerMethod);
        String topic = message.getTopic();
        logger.info("===topic: {}", topic);
        String context = new String(message.getBody());
        logger.info("===context: {}", context);

        if (StringUtils.isEmpty(context)) {
            logger.error("MQ消息为空或NULL值");
        }
        // 业务处理

    }

}